<?php

namespace App\Http\Controllers\Admin\Finance;

use App\Http\Requests\Admin\Finance\CheckIndexRequest;
use App\Http\Requests\Admin\Finance\CheckStoreRequest;
use App\Models\Finance\Check;
use App\Services\Finance\CheckService;
use App\Http\Controllers\Admin\BaseController;
use Illuminate\Http\Request;

class CheckController extends BaseController
{

    public function __construct(CheckService $checkService)
    {
        $this->checkService = $checkService;
    }

    public function create()
    {
        return view('finance.check.create');
    }

    public function store(CheckStoreRequest $request)
    {
        $this->checkService->create($request);

        flash('修改成功')->success()->important();

        return $this->redirect($request);
    }

    public function edit($id)
    {
        $check = $this->checkService->checkRepository->getById($id);

        return view('finance.check.edit', compact('check'));
    }

    public function update(CheckStoreRequest $request, $id)
    {
        $this->checkService->update($request, $id);

        flash('更新游戏成功')->success()->important();

        return $this->redirect($request);
    }

    //核查
    public function index(CheckIndexRequest $request)
    {
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;

        $reqGameId = $request->game_id;
        $reqChannelId = $request->channel_id;

        $incomes = $this->checkService->getIncome($request);
        $checkInfo = $this->checkService->getCheckInfo($request);

        return view('finance.check.index', compact(['incomes', 'checkInfo', 'reqStartTime', 'reqEndTime', 'reqGameId', 'reqChannelId']));
    }
}
